#include "linux/module.h"
#include "linux/init.h"

#include "linux/platform_device.h"

int my_probe(struct platform_device *pdev)
{
    struct resource *res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
    printk("这是my_probe\n");
    printk("=============fun1=============\n");
    if (pdev->num_resources >= 2)
    {
        struct resource *res_mem = &pdev->resource[0];
        struct resource *res_irq = &pdev->resource[1];
        printk("资源A:%llx--%llx\n", res_mem->start, res_mem->end);
        printk("资源B:%lld--%lld\n", res_irq->start, res_irq->end);
    }
    printk("=============fun2=============\n");

    if (!res)
        printk("获取失败\n");
    printk("资源A:%lld--%lld\n", res->start, res->end);

    return 0;
}
int my_remove(struct platform_device *pdev)
{
    printk("这是my_remove\n");
    return 0;
}

struct platform_driver my_platform_driver = {
    .probe = my_probe,
    .remove = my_remove,
    .driver = {
        .name = "LYH_platform_device",
        .owner = THIS_MODULE,
    },
};

int __init my_platform_driver_init(void)
{
    int ret;
    printk("驱动加载\n");
    ret = platform_driver_register(&my_platform_driver);
    if (ret < 0)
    {
        printk("平台驱动注册失败\n");
        return -1;
    }
    printk("平台驱动注册成功\n");
    return 0;
}
void __exit my_platform_driver_exit(void)
{
    platform_driver_unregister(&my_platform_driver);
    printk("驱动卸载\n");
}

module_init(my_platform_driver_init);
module_exit(my_platform_driver_exit);
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("LYH");